/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Connection;

/**
 *
 * @author Adrian
 */
import Entities.Kendaraan;
import Entities.Karyawan;
import java.sql.*;

public class Koneksi {

    static Connection conn = null;
    static String urlValue = "";
//    public int status;
    public static boolean status;
    public static Statement stmt = null;
    public static ResultSet rset;
    public static String query;

    public Koneksi() {
        getConnection();
    }

    public static boolean getConnection(String user, String password) {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            urlValue = "jdbc:oracle:thin:@localhost:1521:XE";
            conn = (Connection) DriverManager.getConnection(urlValue, user, password);
            System.out.println("Koneksi berhasil");
            status = true;
        } catch (Exception ex) {
            System.out.println("Koneksi gagal");
            status = false;
        }
        return status;
    }

    public static Connection getConnection() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            urlValue = "jdbc:oracle:thin:@localhost:1521:XE";
            conn = (Connection) DriverManager.getConnection(urlValue, "rplbo", "rplbo");
            System.out.println("Koneksi berhasil");
        } catch (Exception ex) {
            System.out.println("Koneksi gagal");
        }
        return conn;
    }

    //Method pembantu Eksekusi
    public static ResultSet select(String query) throws SQLException {
        Koneksi.getConnection();
        stmt = Koneksi.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rset = stmt.executeQuery(query);
        return rset;
    }

    public static void updateData(String query) throws SQLException {
        stmt = Koneksi.getConnection().createStatement();
        stmt.executeUpdate(query);
    }

    public static void execute(String query) throws SQLException {
        conn = Koneksi.getConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        stmt.execute(query);
    }
}
